package com.tal.bcc.pad.cloud.thread;

import com.tal.bcc.pad.cloud.entity.CloudResult;
import com.tal.bcc.pad.cloud.listener.StsUploadListener;
import com.tal.bcc.pad.cloud.upload.XesUpload;

import java.util.UUID;

public class UploadTask implements Runnable {
    XesUpload xesUpload;
    StsUploadListener uploadListener;
    String taskId;
    private int count = 0;
    CloudResult mCloudResult;
    StsUploadListener stsUploadListener = new StsUploadListener() {
        public void onProgress(CloudResult result, int percent) {
            UploadTask.this.uploadListener.onProgress(result, percent);
        }

        public void onSuccess(CloudResult result) {
            UploadTask.this.uploadListener.onSuccess(result);
        }

        public void onError(CloudResult result) {
            if ("".equals(result.getErrorMsg()) || result.getErrorMsg() ==null) {
                result.setErrorMsg("上传文件错误");
            }

            UploadTask.this.uploadListener.onError(result);
        }
    };

    public UploadTask( CloudResult cloudResult, StsUploadListener uploadListener) {
        this.uploadListener = uploadListener;
        this.xesUpload = new XesUpload();
        this.mCloudResult = cloudResult;
    }

    public void setTaskId() {
        this.taskId = UUID.randomUUID().toString();
    }

    private void uploadFile() {
        if (this.mCloudResult != null) {
            this.xesUpload.asyncUpload(this.mCloudResult, this.stsUploadListener);
        }
    }

    public void run() {
        this.uploadFile();
    }
}
